/**
 *
 */
import OpenApi;
import OpenApi.OpenApiUtil;

extends OpenApi;


init(config: OpenApiUtil.Config){
  super(config);
  @endpointRule = '';
  
  checkConfig(config);
  @endpoint = getEndpoint('bailianchatbot', @regionId, @endpointRule, @network, @suffix, @endpointMap, @endpoint);
}

function getEndpoint(productId: string, regionId: string, endpointRule: string, network: string, suffix: string, endpointMap: map[string]string, endpoint: string) throws: string{
  if (!$isNull(endpoint)) {
    return endpoint;
  }
  
  if (!$isNull(endpointMap) && !$isNull(endpointMap[regionId])) {
    return endpointMap[regionId];
  }
  return OpenApiUtil.getEndpointRules(productId, regionId, endpointRule, network, suffix);
}

model SseChatRequest {
  appId?: string(name='AppId', description='This parameter is required.', example='chatbot-cn-dDmF3jcdVf'),
  command?: string(name='Command', example='TIMEOUT'),
  senderId?: string(name='SenderId', example='uid129312098593'),
  senderNick?: string(name='SenderNick'),
  sessionId?: string(name='SessionId', example='15e04f27-acd7-489d-872f-1d68f7535e33'),
  utterance?: string(name='Utterance', description='This parameter is required.', nullable=false),
  vendorParam?: string(name='VendorParam'),
  workspaceId?: string(name='WorkspaceId', description='This parameter is required.', example='llm-g7jspxljq8k909h3'),
}

model SseChatResponseBody = {
  code?: string(name='Code', example='200'),
  data?: any(name='Data'),
  message?: string(name='Message', example='success'),
  requestId?: string(name='RequestId', example='30D68C4C-4512-58A7-A328-568015B39A02'),
  success?: boolean(name='Success', example='True'),
}

model SseChatResponse = {
  headers?: map[string]string(name='headers'),
  statusCode?: int32(name='statusCode'),
  body?: SseChatResponseBody(name='body'),
}

/**
 * @summary SSE问答接口
 *
 * @param request SseChatRequest
 * @param runtime runtime options for this request RuntimeOptions
 * @return SseChatResponse
 */
async function sseChatWithOptions(request: SseChatRequest, runtime: $RuntimeOptions): SseChatResponse {
  request.validate();
  var query = {};
  if (!$isNull(request.appId)) {
    query['AppId'] = request.appId;
  }
  if (!$isNull(request.command)) {
    query['Command'] = request.command;
  }
  if (!$isNull(request.senderId)) {
    query['SenderId'] = request.senderId;
  }
  if (!$isNull(request.senderNick)) {
    query['SenderNick'] = request.senderNick;
  }
  if (!$isNull(request.sessionId)) {
    query['SessionId'] = request.sessionId;
  }
  if (!$isNull(request.utterance)) {
    query['Utterance'] = request.utterance;
  }
  if (!$isNull(request.vendorParam)) {
    query['VendorParam'] = request.vendorParam;
  }
  if (!$isNull(request.workspaceId)) {
    query['WorkspaceId'] = request.workspaceId;
  }
  var req = new OpenApiUtil.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApiUtil.Params{
    action = 'SseChat',
    version = '2024-11-05',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  if ($isNull(@signatureVersion) || @signatureVersion != 'v4') {
    return callApi(params, req, runtime);
  } else {
    return execute(params, req, runtime);
  }
}

/**
 * @summary SSE问答接口
 *
 * @param request SseChatRequest
 * @return SseChatResponse
 */
async function sseChat(request: SseChatRequest): SseChatResponse {
  var runtime = new $RuntimeOptions{};
  return sseChatWithOptions(request, runtime);
}

